package edu.hnnu.sport_event.controller;

import edu.hnnu.sport_event.entity.Admin;
import edu.hnnu.sport_event.entity.Student;
import edu.hnnu.sport_event.service.AdminServiceImp;
import edu.hnnu.sport_event.service.StudentServiceImp;
import edu.hnnu.sport_event.utils.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("modify")
public class ModifyInfoController {

    @Resource
    AdminServiceImp adminServiceImp;

    @Resource
    StudentServiceImp studentServiceImp;

    @RequestMapping("getadmin")
    public Admin getAdmin(Integer id) {
        if (null == id) return null;
        return adminServiceImp.getAdmin(id);
    }

    @RequestMapping("getstudent")
    public Student getStudent(Integer id) {
        if (null == id) return null;
        return studentServiceImp.getStudentById(id);
    }

    @RequestMapping("admin")
    public Result modifyAdmin(Admin admin) {
        System.out.println(admin);
        int res = adminServiceImp.update(admin);
        if (res > 0) return Result.success("信息修改成功");
        return Result.error("修改失败");
    }

    @RequestMapping("student")
    public Result modifyStudent(Student student) {
        int res = studentServiceImp.updateStudent(student);
        if (res > 0) return Result.success("信息修改成功");
        return Result.error("修改失败");
    }

}
